home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 12 / Cream of the Crop 12 (Part II) / Cream of the Crop 12 (Part II).iso / OS2 / HELLO.ZIP / os2 / JCJULCAL.CMD < prev    next >
Encoding:
Text File  |  1996-04-02  |  3.7 KB  |  90 lines

  1. /******************************* REXX *********************************/
  2. /*  REXX Function to calculate and return Gregorian (Calendar)        */
  3. /*  dates.  This is a port of an ANSI COBOL program which calculated  */
  4. /*  Gregorian dates base on passed Julian dates.  The original        */
  5. /*  program and the REXX port were both done by Jaime A. Cruz, Jr.    */
  6. /*  This program is released to the public domain.  You may contact   */
  7. /*  the author at 72267.1372@compuserve.com, or jcruz@ibm.net         */
  8. /**********************************************************************/
  9. /*                   Table of days in each month.                     */
  10. /**********************************************************************/
  11. month.0 = 12
  12. month.1 = 31
  13. month.2 = 28
  14. month.3 = 31
  15. month.4 = 30
  16. month.5 = 31
  17. month.6 = 30
  18. month.7 = 31
  19. month.8 = 31
  20. month.9 = 30
  21. month.10 = 31
  22. month.11 = 30
  23. month.12 = 31
  24.  
  25. /**********************************************************************/
  26. /*        Argument passed must be in yyddd or yyyyddd format          */
  27. /**********************************************************************/
  28. Parse Upper Arg jul_date, .
  29. Select
  30. /**********************************************************************/
  31. /*  If a five-digit Julian Date was passed, extract the century from  */
  32. /*  the system, and set a flag indicating the short form was used.    */
  33. /**********************************************************************/
  34.    When Length(jul_date) = 5 Then
  35.       Do
  36.          Parse Value jul_date With 1 jul_year 3 ,
  37.                                    3 jul_day 6
  38.          jul_cent = Left(Date('S'), 2)
  39.          short = 1
  40.       End
  41. /**********************************************************************/
  42. /*  If a seven-digit Julian Date was passed, we will use the century  */
  43. /*  the user specified.                                               */
  44. /**********************************************************************/
  45.    When Length(jul_date) = 7 Then
  46.       Do
  47.          Parse Value jul_date With 1 jul_cent 3 ,
  48.                                    3 jul_year 5 ,
  49.                                    5 jul_day 8
  50.          short = 0
  51.       End
  52. /**********************************************************************/
  53. /*  If an unrecognized date format was used, then we'll default to    */
  54. /*  today's date.                                                     */
  55. /**********************************************************************/
  56.    Otherwise
  57.       Do
  58.          jul_day = Date('D')
  59.          jul_cent = Left(Date('S'), 2)
  60.          jul_year = Left(Date('O'), 2)
  61.          short = 0
  62.       End
  63. End
  64.  
  65. If JCLepYer(jul_cent || jul_year) Then
  66.    month.2 = 29
  67.  
  68. /**********************************************************************/
  69. /*         Build the Gregorian year (short or long format).           */
  70. /**********************************************************************/
  71. If short Then
  72.    greg_year = Right(jul_year, 2, '0')
  73. Else
  74.    greg_year = Right(jul_cent, 2, '0') || Right(jul_year, 2, '0')
  75.  
  76. /**********************************************************************/
  77. /*                   Calculate the month and day.                     */
  78. /**********************************************************************/
  79. Do i = 1 To 12 Until jul_day < 1
  80.    jul_day = jul_day - month.i
  81. End
  82. jul_day = jul_day + month.i
  83. greg_day = Right(jul_day, 2, '0')
  84. greg_month = Right(i, 2, '0')
  85.  
  86. /**********************************************************************/
  87. /*        Return the calculated Gregorian date to the invoker         */
  88. /**********************************************************************/
  89. Return greg_month || '/' || greg_day || '/' || greg_year
  90.